package com.hospital.tools;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.hospital.xml.HosHandler;

import android.util.Log;

public class ArrayListTool {

	public List<HashMap<String,String>> getList(String xml,HashMap<String ,String> in){

		InputStream ret=new SoapHelper().getXmlStream(xml, "Serviceprocessing");
		/// InputStream ret=new SoapHelper().getXmlStream(xml, "Serviceprocessing");//1111111
		//InputStream ret为得到的待解析的xml

		List<HashMap<String,String>> entrys=null;
		entrys=new ArrayList<HashMap<String,String>>(0);
		entrys.add(in);
		parse(ret, entrys);
		return entrys;

	}
	public List<HashMap<String,String>> getList2(String xml,HashMap<String ,String> in){

		InputStream ret=new SoapHelper().getXmlStream2(xml, "Process");
		/// InputStream ret=new SoapHelper().getXmlStream(xml, "Serviceprocessing");//1111111
		//InputStream ret为得到的待解析的xml

		List<HashMap<String,String>> entrys=null;
		entrys=new ArrayList<HashMap<String,String>>(0);
		entrys.add(in);
		parse(ret, entrys);
		return entrys;

	}



	public List<HashMap<String,String>> getXMLParse(String xml,HashMap<String ,String> in){

		InputStream ret=new ByteArrayInputStream(xml.getBytes());
		List<HashMap<String,String>> entrys=null;
		entrys=new ArrayList<HashMap<String,String>>(0);
		entrys.add(in);
		parse(ret, entrys);
		return entrys;

	}

	public void parse(InputStream ret,List<HashMap<String,String>> entrys){



		SAXParserFactory factory=SAXParserFactory.newInstance();

		try {
			XMLReader reader=factory.newSAXParser().getXMLReader();
			//解析////////////////////////////////////////////
			reader.setContentHandler(new HosHandler(entrys));
			reader.parse(new InputSource(ret));

		} catch (Exception e) {

		}
	}





	public HashMap<String,String> getUpdateInfo(){
		List<HashMap<String,String>> entrys=null;
		entrys=new ArrayList<HashMap<String,String>>(0);
		entrys.add(new HashMapMader().getUpdateInfoMap());
		try {
			parse(new URL("http://122.227.214.107:8855/update.xml").openStream(), entrys);
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		return entrys.get(0);

	}




}
